<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
  </head>
  <body>
    <input type="text" name="password" />
    <input type="text" name="confirm_password" />
    <br />
    <span name="msg"></span>
  </body>
  <script>
    function query(name) {
      //必须飘号
      return document.querySelector(`[name='${name}']`);
    }

    let inputs = document.querySelectorAll(
      '[name="password"],[name="confirm_password"]'
    );
    let span = query("msg");

    [...inputs].map(item => {
      item.addEventListener("keyup", function() {
        let msg = "";
        if (query("password").value != query("confirm_password").value) {
          msg = "密码不一致";
        }
        span.innerHTML = msg;
      });
    });
   
  </script>
</html>
